package com.binyouwei.designpatterns.structural_type.flyweight;

/**
 * @author 宾有为
 * @date 2024/7/3 21:07
 * @link https://blog.csdn.net/baidu_41616022?type=blog
 * @describe：享元模式 - 通过共享对象来减少创建大量相似对象时的内存消耗。
 **/
public class FlyweightMain {
    private static final String colors[] = {"Red", "Green", "Blue", "White", "Black"};

    public static void main(String[] args) {
        FlyweightCircle circle = (FlyweightCircle) ShapeFactory.getCircle(getRandomColor());
        circle.setX(getRandomX());
        circle.setY(getRandomY());
        circle.setRadius(100);
        circle.draw();
    }

    private static String getRandomColor() {
        return colors[(int)(Math.random() * colors.length)];
    }

    private static int getRandomX() {
        return (int)(Math.random() * 100);
    }

    private static int getRandomY() {
        return (int)(Math.random() * 100);
    }
}
